import copy
import math
import time

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from matplotlib.pyplot import MultipleLocator
from PIL import Image

from .dealSgy import read_sgy, gain
from .plot import wiggle_plot, wiggle_plot1, wiggle_plot2
# from clipStack import get_st_stkb
from .clipStack2 import get_inlay_data
from utils.index import resource_path


# 读取分层文件
def read_layer(file_path, isDraw = 1):
    """
    读取分层文件
    :param file_path: 文件路径
    :param isDraw: 是否画线，默认为1
    :return: {
            "zu" : df.iloc[:, 0],  # 分组
            "ywdh" : df.iloc[:, 1],  # 英文代号
            "dep" : df.iloc[:, 2],  # 底深
            "font" : df.iloc[:, 3],  # 文字大小
            "fzt" : df.iloc[:, 4],  # 文字时间
            "py" : df.iloc[:, 5],  # 文字深度偏移
            "ywdhpy" : df.iloc[:, 6],  # 代号深度
            "font1" : df.iloc[:, 7],  # 代号大小
        }
    """
    if isDraw == 1:  # 分层文件，读取
        df = pd.read_excel(file_path, sheet_name=0)  # sheet_name指定工作表编号或名称
        df.fillna('', inplace=True)  # 如果为空，则替换为空字符串
        layer = {
            "zu" : df.iloc[:, 0],  # 分组
            "ywdh" : df.iloc[:, 1],  # 英文代号
            "dep" : df.iloc[:, 2],  # 底深
            "font" : df.iloc[:, 3],  # 文字大小
            "fzt" : df.iloc[:, 4],  # 文字时间
            "py" : df.iloc[:, 5],  # 文字深度偏移
            "ywdhpy" : df.iloc[:, 6],  # 代号深度
            "font1" : df.iloc[:, 7],  # 代号大小
        }
    else:
        layer = {
            "zu": [],  # 分组
            "ywdh": [],  # 英文代号
            "dep": [],  # 底深
            "font": [],  # 文字大小
            "fzt": [],  # 文字时间
            "py": [],  # 文字深度偏移
            "ywdhpy": [],  # 代号深度
            "font1": [],  # 代号大小
        }

    return layer


# 计算不同深度采样间隔的数量，不考虑补芯高
def get_deep_interval(cdp, deep_start, deep_end, direction):
    """
    计算不同深度采样间隔的数量，不考虑补芯高
    :param cdp: 拉平cdp数据
    :param deep_start: 拉平绘制深度-开始
    :param deep_end: 拉平绘制深度-结束
    :param direction: 深度方向
    :return: {
        "brfi1": brfi1, # 深度间隔为5或10的数量
        "brfi2": brfi2  # 深度间隔为20的数量
    }
    """
    brfi1 = 0  # 5或10
    brfi2 = 0  # 20
    brfl = len(cdp)  # 拉平的数据道数
    for ii in range(0, brfl - 1):
        # 仅考虑绘制范围内的数据
        if cdp[ii] > deep_end or cdp[ii] < deep_start:
            continue
        if direction == 0:  # 数据深度从浅到深
            if cdp[ii] - cdp[ii + 1] > -15:  # 间隔小于15，可以为5,10
                brfi1 = brfi1 + 1
            else:  # 20
                brfi2 = brfi2 + 1
        else:  # 数据深度从深到浅
            if cdp[ii] - cdp[ii + 1] > 15:  # 20
                brfi2 = brfi2 + 1
            else:  # 间隔可以为5,10
                brfi1 = brfi1 + 1
    return {
        "brfi1": brfi1,
        "brfi2": brfi2
    }


# 计算井口和检波器间的最小距离的道号
def get_min_distance(file, wellx, welly):
    """
    计算井口和检波器间的最小距离的道号
    :param file: 地面数据对象
    :param wellx: 走廊数据的wellx的第一个值
    :param welly: 走廊数据的welly的第一个值
    :return: 井口和检波器间的最小距离的道号
    """
    stkcdp = 0  # 最小距离的下标
    maxjuli = 9999999  # 存放最小距离
    for i in range(file["ntraces"]):
        juli = math.sqrt((wellx*1.0 - file["cdpx"][i])** 2 + (welly*1.0 - file["cdpy"][i]) ** 2)
        if juli < maxjuli:  # 计算井口与检波点的最小距离
            maxjuli = juli
            stkcdp = i

    print(f"=====*****=====\n地面距井口最近的道：{stkcdp + 1}")
    return stkcdp


# 修改柱子图像像素的大小，根据图片像素大小与柱子的深度的比例
def update_image_dpi(image_path, height, width, other_length):
    pass


def print_landmark(str, time=0):
    print("=====*****=====")
    print(str, f"{time}s")


def vspplot(cfg, progress_wrapper):
    progress_wrapper.setValue(0)  # 进度条开始
    start = time.time()

    s1 = read_sgy(cfg['lp'])  # 拉平文件，读取
    layer = read_layer(cfg['fc'], cfg['fcx'])  # 分层文件读取
    im = plt.imread(cfg['zhuzi'])  # 岩性柱子，读取图像文件
    im = im.swapaxes(1, 0)  # 用于交换数组的两个轴，将高度和宽度进行交换

    # 获取偏移数据，生成指定道数的走廊数据和滤波走廊数据
    st_path = resource_path("./static/sgy/repeat_stk.sgy")  # 走廊
    stkbf_path = resource_path("./static/sgy/repeat_stkbp.sgy")  # 滤波走廊
    sei_path = resource_path("./static/sgy/sei.sgy")
    # sei_origin_path = r"E:\vspData\ATU101\sei.sgy"
    trace_num = 10  # 走廊的道数
    sei_origin = read_sgy(cfg["sei_origin"])  # 地面文件原始
    # 获取偏移数据，生成指定道数的走廊数据和滤波走廊数据，截取地面数据
    s2 = read_sgy(st_path)  # 走廊文件，读取
    stkcdp = get_min_distance(sei_origin, s2["wellx"][0], s2["welly"][0])  # 地面数据中井口和检波点距离最近的道的下标
    stack = get_inlay_data(cfg["sei"], sei_path, cfg["sein"], cfg["stk"], st_path, cfg["stkbf"], stkbf_path, stkcdp+1, trace_num)

    # 右侧偏移数据示例
    # stkbf_path = r"E:\vspData\斜井\repeat_stkbp.sgy"  # 滤波走廊
    # st_path = r"E:\vspData\斜井\repeat_stk.sgy"  # 走廊
    # sein_path = r"E:\vspData\斜井\psdm_stk_inl994_1394_0914vsp_mu_filter_scale_inq_3D_tm_inlne1194AGC.sgy"  # 地面
    # stack = {
    #     "flag": 1,
    #     "trace_offset": [
    #         {"trace_index": 11, "non_zero_time": 5216.0},
    #         {"trace_index": 12, "non_zero_time": 5696.0},
    #         {"trace_index": 13, "non_zero_time": 5760.0},
    #         {"trace_index": 14, "non_zero_time": 5844.0},
    #         {"trace_index": 15, "non_zero_time": 5894.0},
    #         {"trace_index": 16, "non_zero_time": 5920.0},
    #         {"trace_index": 17, "non_zero_time": 5942.0},
    #         {"trace_index": 18, "non_zero_time": 5964.0},
    #         {"trace_index": 19, "non_zero_time": 5980.0},
    #         {"trace_index": 20, "non_zero_time": 5994.0},
    #         {"trace_index": 21, "non_zero_time": 6006.0},
    #         {"trace_index": 22, "non_zero_time": 6018.0},
    #         {"trace_index": 23, "non_zero_time": 6028.0},
    #     ],
    #     "trace_start_offset": 0,
    #     "trace_num_offset": 23,
    #     "trace_num": 10
    # }
    #
    # stkbf_path = r"E:\vspData\斜井\repeat_stkbp.sgy"  # 滤波走廊
    # st_path = r"E:\vspData\斜井\repeat_stk.sgy"  # 走廊
    # sein_path = r"E:\vspData\斜井\01地面.sgy"  # 地面

    s3 = read_sgy(stkbf_path)  # 滤波走廊文件，读取
    s4 = read_sgy(sei_path)  # 斜井地面文件，读取


    print_landmark("文件读取完成", time.time()-start)

    # 设置极性
    if cfg['lpjx'] == 0:
        s1["data"] = -s1["data"]
    if cfg['stkjx'] == 1:  # 因为坐标轴颠倒，所以与其他的数据不同
        s2["data"] = -s2["data"]
    if cfg['stkbfjx'] == 1:
        s3["data"] = -s3["data"]
    if cfg['seijx'] == 0:
        s4["data"] = -s4["data"]

    print_landmark("极性设置完成", time.time()-start)

    # 拉平文件，如果采样间隔小于1ms，则数据进行抽稀
    if s1["dt"] < 1:
        sca = int(1 / s1["dt"])
        s1["dt"] = 1.0
        s1['data'] = s1["data"][::, ::sca]

    print_landmark("拉平抽稀完成", time.time()-start)

    # 设置增益agc
    if cfg['lpagc'] == 0:
        s1['data'] = gain(s1, cfg['agc'])
    if cfg['stkagc'] == 0:
        s2['data'] = gain(s2, cfg['agc'])
    if cfg['stkbfagc'] == 0:
        s3['data'] = gain(s3, cfg['agc'])
    if cfg['seiagc'] == 0:
        s4['data'] = gain(s4, cfg['agc'])

    print_landmark("数据AGC完成", time.time()-start)
    progress_wrapper.setValue(13)

    # Margins, CSS like: top, right, bottom, left.
    mt, mr, mb, ml = 0.3, 0.5, 0.3, 0.5
    tpi = cfg['tpi']  # 深度比例尺
    ips = cfg['ips']  # 时间比例尺

    # 获取不同深度采样间隔的数量
    deep_interval = get_deep_interval(s1["cdp"], cfg["lpsd"], cfg["lped"], cfg["direction"])
    brfi1 = deep_interval["brfi1"]  # 5,10
    brfi2 = deep_interval["brfi2"]  # 20

    # 拉平
    # 深度在画布上的长度为(end - start) / tpi
    # brfi1占据半道，brfi2占据1道
    seismic_width5 = brfi1 / 2 / tpi + (brfi2 + 2) / tpi  # 拉平深度在画布上的宽度，这里将brfi1视为深度间隔为10的数量
    seismic_height_raw = ips * (cfg['trange'][1] - cfg['trange'][0])  # 拉平在画布上的高度
    w1 = seismic_width5
    # 柱子
    imsize = np.shape(im)  # 图片大小，(1984, 3431, 4)，高度，宽度，通道数rgba
    print(f"柱子图片大小：{imsize}")
    scal = (imsize[1] - 158) / (cfg['zhuzidepmax'] - cfg['zhuzidepmin'])  # 像素与深度的比，图片其他部分的像素为158
    # 拉平的绘制范围是start - 20 + kb 至 end + 20 + kb
    if cfg['zhuzidepmax'] < cfg['lped'] + 20 + cfg['kb']:  # 柱子小于要绘制的深度，柱子的长度由柱子决定
        w6 = ((cfg['zhuzidepmax']- (cfg['lpsd'] + cfg['kb'] - 20)) * scal + 158) / scal / (cfg['lped'] - cfg['lpsd'] + 40) * seismic_width5
    else:  # 柱子长度由拉平绘制深度决定
        w6 = ((cfg['lped'] + 40 - cfg['lpsd']) * scal + 158) / scal / (cfg['lped'] - cfg['lpsd'] + 40) * seismic_width5
    w8 = imsize[0] / scal / (cfg['lped'] - cfg['lpsd'] + 40) * seismic_width5  # 岩性柱子的高度
    # 走廊和滤波走廊
    w2 = (s2["ntraces"] + 1) / tpi  # 每道数据都占据1道
    w3 = (s2["ntraces"] + 1) / tpi  # 和走廊一样
    # 地面数据的宽度
    w4 = (cfg['sein'] + 1) / tpi
    # 柱子表头的像素，136，表尾22
    w7 = 136 / scal / (cfg['lped'] - cfg['lpsd'] + 40) * seismic_width5  # 136

    print_landmark(f"w1:{w1}, w2:{w2}, W3:{w3}, w4:{w4}, lpH:{seismic_height_raw}, zhuH:{w8}， zhuW:{w6}")

    h = mb + seismic_height_raw + mt + w8  # inches，总高
    seismic_width = w1 + w2 + w3 + w4 + mr + ml  # 画布的宽度，总宽
    w = seismic_width

    # 由长度转为比例
    seismic_left = ml / seismic_width
    seismic_bottom = mb / h
    seismic_width_fraction1 = w1 / seismic_width  # 拉平宽度
    seismic_width_fraction2 = w2 / seismic_width  # 走廊
    seismic_width_fraction3 = w3 / seismic_width  # 滤波走廊
    seismic_width_fraction4 = w4 / seismic_width  # 地面数据
    seismic_width_fraction6 = w6 / seismic_width  # 岩性柱子
    seismic_width_fraction7 = (w6 - w7 - w1) / seismic_width  # 柱子需要移动的距离，为了柱子能与拉平对齐
    seismic_height_fraction = seismic_height_raw / h  # 拉平高度
    seismic_height_fraction2 = w8 / h  # 柱子高度

    # 计算走廊和滤波走廊的宽度比例和向左偏移的比例数值
    width_ratio = (stack["trace_num_offset"] + 1) / tpi / seismic_width
    if stack["flag"] == -1:  # 井斜向左偏移
        left_offset_ratio = stack["trace_start_offset"] / tpi / seismic_width  # 13
        offset_num = 1  # 走廊1，滤波走廊2，地面3
    else:  # 井斜向右偏移
        left_offset_ratio = (stack["trace_num_offset"] - stack["trace_num"]) / tpi / seismic_width  # 13
        offset_num = 0  # 走廊0，滤波走廊1，地面2

    # 坐标系位置
    # left，bottom，width，height
    rect_line1 = [seismic_left, seismic_bottom, seismic_width_fraction1,
                  seismic_height_fraction]  # 拉平
    # width和left要改，width+13， left-13
    rect_line2 = [seismic_left + seismic_width_fraction1 - left_offset_ratio * offset_num,
                  seismic_bottom,
                  width_ratio,
                  seismic_height_fraction]  # 走廊
    # width和left要改，width+13， left-13
    rect_line3 = [seismic_left + seismic_width_fraction1 + seismic_width_fraction2 - left_offset_ratio * (offset_num + 1),
                  seismic_bottom,
                  width_ratio,
                  seismic_height_fraction]  # 滤波走廊

    rect_line4 = [seismic_left + seismic_width_fraction1 + seismic_width_fraction2 + seismic_width_fraction3 - left_offset_ratio * (offset_num + 2),
                  seismic_bottom,
                  seismic_width_fraction4,
                  seismic_height_fraction]  # 地面
    rect_line5 = [seismic_left + seismic_width_fraction1 + seismic_width_fraction2 + seismic_width_fraction3 - left_offset_ratio * (offset_num + 2),
                  seismic_bottom + seismic_height_fraction,
                  seismic_width_fraction4,
                  1.0 - seismic_bottom - seismic_height_fraction - seismic_height_fraction2]  # crossline
    rect_line6 = [seismic_left - seismic_width_fraction7,  # 柱子与拉平对齐
                  seismic_bottom + seismic_height_fraction,
                  seismic_width_fraction6,
                  seismic_height_fraction2]  # 柱子

    print_landmark("坐标系rect", time.time()-start)
    progress_wrapper.setValue(25)

    # 显示中文标签
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['mathtext.default'] = 'regular'
    plt.rcParams['axes.unicode_minus'] = False

    fig = plt.figure(figsize=(w, h), facecolor='w', dpi=300)

    # 添加坐标系
    ax1 = fig.add_axes(rect_line1)  # 拉平
    ax2 = fig.add_axes(rect_line2)  # 走廊
    ax3 = fig.add_axes(rect_line3)  # 滤波走廊
    ax4 = fig.add_axes(rect_line4)  # 地面
    ax5 = fig.add_axes(rect_line5)  # crossline
    zhuzi = fig.add_axes(rect_line6)  # 柱子

    # 设置轴
    ax2.set_yticks([])
    ax3.set_yticks([])
    ax2.set_xticks([])
    ax3.set_xticks([])
    ax4.yaxis.set_ticks_position('right')
    ax4.xaxis.set_ticks_position('top')
    ax5.xaxis.set_ticks_position('top')
    ax5.spines['right'].set_visible(False)
    ax5.spines['left'].set_visible(False)
    ax5.spines['top'].set_visible(False)
    ax5.tick_params(which="major", length=0)
    ax5.set_yticks([])

    # 对柱子进行裁剪
    startindex = (cfg['lpsd'] + cfg['kb'] - 20 - cfg['zhuzidepmin']) * scal + 136  # 裁剪范围，开始
    endindex = (cfg['lped'] + cfg['kb'] + 20 - cfg['zhuzidepmin']) * scal + 136  # 裁剪范围，结束
    del_index = []
    for col in range(imsize[1]):
        if col < startindex and col > 136:
            del_index.append(col)
        if col > endindex and col < (imsize[1] - 21):
            del_index.append(col)
    im = np.delete(im, del_index, axis=1)

    # 绘制柱子
    zhuzi.imshow(im, aspect='auto')
    imsize1 = np.shape(im)
    zhuzi.set_xlim(0, imsize1[1])
    zhuzi.set_ylim(0, imsize1[0])

    # 在柱子上画线
    if cfg['fcx'] == 1:
        for ii in range(0, len(layer["dep"])):
            if (layer["dep"][ii] > cfg['lped'] + cfg['kb']) or (layer["dep"][ii] < cfg['lpsd'] + cfg['kb']):
                continue
            xx = (layer["dep"][ii] - cfg['lpsd'] - cfg['kb'] + 20) * scal + 136  # 深度对应的像素点
            zhuzi.plot([xx, xx], [0, imsize1[0]], 'r', lw=2.5 * cfg['lineweight'])
    zhuzi.invert_xaxis()
    zhuzi.invert_yaxis()

    cfg['fontsize'] = cfg['fontsize'] or 30
    [fbmin, fbmax, ax1, fctime] = wiggle_plot(s1, cfg, ax1, layer)
    progress_wrapper.setValue(35)
    ax2 = wiggle_plot1(s2, cfg, ax2, cfg['stkgain'], fctime, fbmax, fbmin, stack)
    progress_wrapper.setValue(45)
    ax3 = wiggle_plot1(s3, cfg, ax3, cfg['stkbfgain'], fctime, fbmax, fbmin, stack, cfg["times"])
    progress_wrapper.setValue(55)
    ax4 = wiggle_plot2(s4, cfg, ax4, cfg['seigain'], fctime, fbmax, fbmin, cfg['seitimes'], 0)  # 镶嵌地面中第一道就是离井口最近的道

    print_landmark("绘制完成", time.time()-start)
    progress_wrapper.setValue(65)

    # 设置坐标轴
    tickfmt = mtick.FormatStrFormatter('%.0f')  # 创建一个格式化器，用于将坐标轴刻度标签格式化为不带小数部分的整数形式，以便在绘图时更清晰地展示数据
    # 拉平
    # 调整绘制的顺序，使拉平的刻度和标签避免被岩性柱子覆盖
    ax1.set_zorder(2)
    ax1.set_ylabel('Time(ms)', fontsize=cfg['fontsize'] - 20)
    ax1.set_xlabel('Depth(m)', fontsize=cfg['fontsize'] - 20, ha='center')
    y_major_locator = MultipleLocator(cfg['timeskip'])  # 设置坐标轴刻度间隔
    ax1.yaxis.set_major_locator(y_major_locator)
    ticks_loc = np.arange(int(ax1.viewLim.x1), int(ax1.viewLim.x0), cfg['skip3'])
    if (cfg['lped'] - ticks_loc[-1]) < 200:
        ticks_loc[-1] = cfg['lped']
    else:
        np.append(ticks_loc, cfg['lped'])
        ticks_loc = np.append(ticks_loc, cfg['lped'])
    ax1.set_xticks(ticks_loc)
    ax1.set_xticklabels(ticks_loc, fontsize=cfg['fontsize'] - 20)
    ax1.xaxis.set_major_formatter(tickfmt)
    ax1.yaxis.set_major_formatter(tickfmt)
    ax1.set_ylim(1000 * cfg['trange'][1] or 1000 * s1.tbasis[-1], 1000 * cfg['trange'][0])
    ax1.xaxis.set_ticks_position('top')
    ax1.xaxis.set_label_position('top')
    ax1.tick_params(axis='x', width=cfg['lineweight'], colors='black')
    # 走廊
    ax2.set_ylim(1000 * cfg['trange'][1] or 1000 * s1.tbasis[-1], 1000 * cfg['trange'][0])
    # 滤波走廊
    ax3.set_ylim(1000 * cfg['trange'][1] or 1000 * s1.tbasis[-1], 1000 * cfg['trange'][0])
    # 地面
    # 调整绘制的顺序，使地面地震的刻度和标签避免被crossLine覆盖
    ax4.set_zorder(2)
    ax4.set_ylim(1000 * cfg['trange'][1] + cfg['seitimes'] or 1000 * s1.tbasis[-1], 1000 * cfg['trange'][0] + cfg['seitimes'])
    y_major_locator1 = MultipleLocator(cfg['timeskip'])
    ax4.yaxis.set_major_locator(y_major_locator1)
    ticks_loc = np.arange(20, 20*(cfg['sein']-10)+20, 300)
    ticks_loc = np.append(ticks_loc, 20 * cfg['sein'] + 20)
    ax4.set_xticks(ticks_loc)
    # InLine
    ticklable = sei_origin["inlin"][stkcdp : stkcdp+cfg['sein']-10 : 15]
    ticklable = np.append(ticklable, 'InLine')
    ax4.set_xticklabels(ticklable, fontsize=cfg['fontsize'] - 20)
    # CrossLine
    ax5.set_xlim(0, 20 * cfg['sein'] + 20)
    ax5.set_xticks(ticks_loc)
    ticklable = sei_origin["crosslin"][stkcdp : stkcdp+cfg['sein']-10 : 15]
    ticklable = np.append(ticklable, 'CrossLine')
    ax5.set_xticklabels(ticklable, fontsize=cfg['fontsize'] - 20)
    # 柱子
    zhuzi.axis('off')

    # 设置层级，走廊位于滤波走廊上方
    ax2.set_zorder(4)
    ax3.set_zorder(3)

    print_landmark("设置坐标轴", time.time()-start)
    progress_wrapper.setValue(67)

    outfile = resource_path("./static/img/provisional.png")
    fig.savefig(outfile, bbox_inches='tight')  # 支持eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff, webp

    progress_wrapper.setValue(85)

    imageRotationPre = Image.open(outfile)
    rotated_image = imageRotationPre.rotate(cfg['angle'], expand=True)
    rotated_image.save(cfg['outfile'])

    print_landmark("完成", time.time()-start)
    progress_wrapper.setValue(100)  # 进度条结束


def inclinedShaftDiagram(cfg, progress_wrapper):
    data_copy = copy.deepcopy(cfg)
    data_copy['tpi'] = data_copy['tpi'] * 2.54
    data_copy['ips'] = data_copy['ips'] / 2.54
    vspplot(data_copy, progress_wrapper)
    return {
        'status': 'success'
    }

if __name__ == "__main__":
    cfg = {
        "tpi": 10.0,
        "ips": 10,
        "lp": "E:/vspData/斜井/Tk1zzlp1mswwbJH.sgy",  # 拉平文件
        "stk": "E:/vspData/斜井/Tk1_最终拉平1ms_COR100.sgy",  # 走廊文件
        "stkbf": r"E:\vspData\斜井\stkb.sgy",  # 滤波走廊文件
        "sei": r"E:\vspData\斜井\psdm_stk_inl994_1394_0914vsp_mu_filter_scale_inq_3D_tm_inlne1194AGC.sgy",  # 地面文件
        "lpjx": 0,  # 拉平极性
        "stkjx": 1,  # 走廊极性
        "stkbfjx": 0,  # 滤波走廊极性
        "seijx": 1,  # 地面极性
        "lpagc": 0,  # 拉平增益
        "stkagc": 0,  # 走廊增益
        "stkbfagc": 0,  # 滤波走廊增益
        "seiagc": 1,  # 地面增益
        "agc": 500,  # 增益时窗
        "fcx": 1,  # 画线
        "fc": "E:/vspData/斜井/X井分层.xlsx",  # 分层文件
        "zhuzi": "E:/vspData/斜井/深地塔科1第3阶段柱子.png",  # 柱子文件
        "lpsd": 20,  # 拉平数据，绘制深度范围-开始
        "lped": 10900,  # 拉平数据，绘制深度范围-结束
        "direction": 0,  # 深度方向，从浅到深
        "trange": [0, 6.5], # 时间范围
        "zhuzidepmin": 0,  # 柱子深度-开始
        "zhuzidepmax": 10950,  # 柱子深度-结束
        "sein": 50,  # 地面绘制的道数
        "skip": 1,  # 道间隔
        "skip2": 1,  # 时间间隔
        "skip3": 300, # 深度间隔
        "kb": 15,  # 补芯高
        "lpgain": 0.75,  # 振幅
        "stkw": 120,  # 走廊切除时窗大小
        "stkdep": 10320,  # 走廊切除深度
        "stkgain": 0.9,
        "stkbfgain": 0.9,
        "times": 627,
        "lineweight": 0.2,  # 线条宽度
        "fontsize": 30,
        "colour": [0, 0, 0],
        "opacity": 1.0,
        "seigain": 0.95,  # 地震绘制道数
        "seitimes": 627,  # 地面时移
        "timeskip": 300, # 时间显示间隔
        "sei": r"E:\vspData\斜井\psdm_stk_inl994_1394_0914vsp_mu_filter_scale_inq_3D_tm_inlne1194AGC镶嵌1.sgy",  # 镶嵌数据
        "trace_start": 404,  # 滤波走廊在镶嵌数据中开始的道号
    }
    data_copy = copy.deepcopy(cfg)
    data_copy['tpi'] = data_copy['tpi'] * 2.54
    data_copy['ips'] = data_copy['ips'] / 2.54
    vspplot(data_copy)

